library   ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;

entity distance is
  port(btn:in std_logic;
		 clearbtn:in std_logic;
       data,data1:out std_logic_vector(3 downto 0));
  end;

architecture rtl of distance is
  begin
    process(btn)
     variable num,num1:std_logic_vector(3 downto 0);
      begin
        if btn'event and btn='1' then 
          if num1="1001" and num="1001" then
             num1:="0000";
             num:="0000";  
      else  if num="1001" then 
                 num:="0000";
                 num1:=num1+1;
             else 
               num:=num+1;
				end if;
          end if;
        end if;
		  if clearbtn='0' then
				num:="0000";
				num1:="0000";
			end if;
      data<=num;
      data1<=num1;
    end process;
  end;

  --data1 wei high